
from Patch import *
X = 0
Y = 1


class Grid2D:
    
    def __init__(self,SCREEN,grid_size,g):
        self.grid = []
        self.grid_size = grid_size
        
        for y in range(grid_size[Y]):
            for x in range(grid_size[X]):
                self.grid.append(Patch(SCREEN,x,y,g))
        
        for p in self.grid:
            lst = []
            for cord in p.genCoordNeigh8(grid_size):
                lst.append(self.getPatch(cord[X],cord[Y]))
            p.setNeigh8(lst)    
    
    def getGrid(self):
        return self.grid        
        
    def getPatch(self,x,y):
        return self.grid[x + y*self.grid_size[X]]
    
    def setPatch(self,coord):
        p = self.getPatch(coord[X],coord[Y])
        p.setState(not p.getState())